package com.linx.common.core.utils;

import com.alibaba.fastjson.JSONObject;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;

import java.util.HashMap;
import java.util.Map;

/**
 * @author linx
 */
public class EncryptionUtil {
    /**
     * 调用海康接口
     *
     * @param body
     * @param url
     * @return
     */
    public static String postHk(String body, String url) {
        /*
          STEP1：设置平台参数，根据实际情况,设置host appkey appsecret 三个参数.
         */
        // 平台的ip端口
        ArtemisConfig.host = "172.16.19.10";
        // 密钥appkey
        ArtemisConfig.appKey = "22911640";
        // 密钥appSecret
        ArtemisConfig.appSecret = "VFZNj6DFIJZHNqgPIP2S";
        /*
          STEP2：设置OpenAPI接口的上下文
         */
        final String ARTEMIS_PATH = "/artemis";
        /*
          STEP3：设置接口的URI地址
         */
        final String previewURLsApi = ARTEMIS_PATH + url;
        Map<String, String> path = new HashMap<String, String>(2) {
            {
                //根据现场环境部署确认是http还是https
                put("http://", previewURLsApi);
            }
        };
        /*
          STEP4：设置参数提交方式
         */
        String contentType = "application/json";
        /*
          STE5：调用接口
         */
        // post请求application/json类型参数
        return ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType, null);
    }

    public static void main(String[] args) {
        try {
            JSONObject params = new JSONObject();
            params.put("pageNo",1);
            params.put("pageSize",1000);
            System.out.println(postHk(params.toString(), "/api/resource/v2/acsdevice/search"));
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
